package com.zzq.springboot1.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @RequestMapping("/login")
//    @ResponseBody无法跳到视图
    //绑定前端的值@RequestParam
    public String login(@RequestParam("username") String username,
                        @RequestParam("password") String password,
                        Model model, HttpSession session){
        //具体业务
        //这是属性值不用引号
        if(!StringUtils.isEmpty(username) && "123456".equals(password)){
//            重定向到映射页面
            session.setAttribute("LoginUser",username);
            return "redirect:/main";
        }else{
            //告诉用户你失败了
            model.addAttribute("msg","账号或密码错误");
            return "index";
        }

    }
}
